﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WebLibraryMaker
{
    public static class ArgumentParser
    {

        public static void ParseArgs(string[] arguments, Pathes pathes, out bool debug, out bool delaySign)
        {
            debug = false;
            delaySign = false;

            string argumentType = "";
            int count = 0;

            foreach (string rawArgument in arguments)
            {
                string argument = rawArgument.Trim();
                
                //parse key
                if (argument.StartsWith("/"))
                {
                    string option = argument.TrimStart('/');

                    switch (option)
                    {
                        case "d":
                            debug = true;
                            break;
                        default:
                            argumentType = option;
                            break;
                    }
                }
                else
                {
                    //parse value
                    count += 1;

                    switch (argumentType)
                    {
                        case "net":
                            pathes.DotNetDirectory = argument;
                            break;
                        case "prj":
                            pathes.ProjectDirectory = argument;
                            break;
                        case "name":
                            pathes.ProjectName = argument;
                            break;
                        case "debug":
                            debug = argument.IndexOf("true", StringComparison.InvariantCultureIgnoreCase) >= 0;
                            break;
                        case "ds":
                            delaySign = argument.IndexOf("true", StringComparison.InvariantCultureIgnoreCase) >= 0;
                            break;
                        case "obj":
                            pathes.IntermediateFolderName = argument;
                            break;
                        case "out":
                            pathes.OutputFolderName = argument;
                            break;
                        case "key":
                            pathes.KeyFileName = argument;
                            break;                            
                        default:
                            count -= 1;
                            break;
                    }

                    argumentType = "";
                }
            }

            if (count < 6)
            {
                throw new Exception("invalid params count: " + count);
            }
        }

    }
}
